package com.foogui.guava;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.junit.Test;

public class MultiMapDemo {
    @Test
    public void multimap() {
        // 创建出来的对象相当与Map<String,Set<String>>
        //Multimap<String, String> multimap = HashMultimap.create();
        // 创建出来的对象相当与Map<String,List<String>>
        Multimap<String, String> multimap= ArrayListMultimap.create();
        multimap.put("1", "1");
        multimap.put("2", "2");
        multimap.putAll("2", Lists.newArrayList("2","2"));
        //multimap中的所有键值对，重复的算多个
        System.out.println(multimap.size());
        System.out.println(multimap.get("2").size());

        //获取multimap中所有的value
        System.out.println(multimap.values());
        //返回Multiset
        System.out.println(multimap.keys().count("2"));
        //返回Map类型
        Map<String, Collection<String>> map = multimap.asMap();
        System.out.println(map);
    }


}
